package com.eightbears.beboy.adapter;

import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eightbears.beboy.R;
import com.eightbears.beboy.base.util.CommonUtils;
import com.eightbears.beboy.entity.CouponsEntity;

public class SetMealListAdapter extends BaseQuickAdapter<CouponsEntity.Coupons, BaseViewHolder> {
    public SetMealListAdapter() {
        super(R.layout.item_set_meal, null);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, CouponsEntity.Coupons coupons) {

        String validDate = String.format(mContext.getString(R.string.text_valid_date),
                CommonUtils.TimeStamp2Date(coupons.getStart_at(), "yyyy-MM-dd"),
                CommonUtils.TimeStamp2Date(coupons.getEnd_at(), "yyyy-MM-dd"));

        baseViewHolder.setText(R.id.tv_name, coupons.getTitle())
                .setText(R.id.tv_price, coupons.getDiscount_price())
                .setText(R.id.tv_price_money, "原价：￥" + coupons.getPrice())
                .setText(R.id.tv_date, validDate)
                .addOnClickListener(R.id.ll_item)
                .addOnClickListener(R.id.tv_shopbook_mealbug);
        TextView tv_price_money = baseViewHolder.getView(R.id.tv_price_money);
        tv_price_money.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

        if (coupons.getStatistics().getSales() != null) {
            baseViewHolder.setText(R.id.tv_sale, "已售 " + coupons.getStatistics().getSales());
        }

        CommonUtils.loadImageView(mContext, coupons.getCover(), R.mipmap.icon_default_shop,
                (ImageView) baseViewHolder.getView(R.id.iv_shop));

    }
}
